package com.anrongtec.zcpt.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.base.BaseActivity;
import com.anrongtec.zcpt.model.News;

import static com.anrongtec.zcpt.fragment.myfocusfragment.NewFragment.newsDataList;

public class NewsDetailActivity extends BaseActivity {

    // ��������
    private TextView news_detail_title;
    private TextView news_detail_author;
    private TextView news_detail_date;
    private TextView news_detail_commentcount;
    private TextView news_detail_body;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_detail);
        this.initView();
        this.initDataBean();
        this.testNewsData();
    }

    /**
     * ��ȡ�������ݲ���ʾ��������ϸ������
     */
    private void initDataBean() {
        // ����positionλ��(��������б���λ��news_id)
        Intent intent = getIntent();
        intent.getExtras();
        Bundle data = intent.getExtras();
        int position = data.getInt("news_id");
        Log.i("���յ�������", String.valueOf(position));

        // ��position��ȡ��Ӧ������
        News news = newsDataList.get(position-1);
        news_detail_title.setText(news.getTitle());
        news_detail_author.setText(news.getAuthor());
        news_detail_date.setText(news.getPubDate());
        news_detail_commentcount.setText(String.valueOf(news.getCommentCount()));
        news_detail_body.setText(news.getBody());

    }

    /**
     * ��ʼ��������ϸ����
     */
    private void initView() {
        news_detail_title = (TextView) findViewById(R.id.news_detail_title);
        news_detail_author = (TextView) findViewById(R.id.news_detail_author);
        news_detail_commentcount = (TextView) findViewById(R.id.news_detail_commentcount);
        news_detail_date = (TextView) findViewById(R.id.news_detail_date);
        news_detail_body = (TextView) findViewById(R.id.news_detail_body);
    }

    /**
     * ���Զ�ȡ�����б����е�����
     */
    private void testNewsData() {
        // ����positionλ��(��������б���λ��news_id)
        Intent intent = getIntent();
        intent.getExtras();
        Bundle data = intent.getExtras();
        int position = data.getInt("news_id");
        Log.i("���Խӵ���б���λ��", String.valueOf(position));
        News news = newsDataList.get(position-1);
        Log.w("����", news.getTitle());
        Log.w("����", news.getAuthor());
        Log.w("��������", news.getPubDate());
        Log.w("������", String.valueOf(news.getCommentCount()));
        Log.w("����", news.getBody());

    }
}
